home *** CD-ROM | disk | FTP | other *** search
- /*
- CDTrackTitle - An XFCN to report the title of the track, if one has been entered
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C CDTrackTitle.c
- link -sn Main=CDTrackTitle -sn STDIO=CDTrackTitle ∂
- -sn INTENV=CDTrackTitle -rt XFCN=42 ∂
- -m CDTrackTitle CDTrackTitle.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
- #include <ToolUtils.h>
-
- /* prototype definitions for functions */
- OSErr ReadQ(short, short *, short *, short *, short *);
- OSErr FindTrackTitle(unsigned long, short, Str255 *);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDTrackTitle
- *
- * Purpose: return the title of this track.
- *
- * Returns: a string, or empty
- *
- * Side Effects:
- *
- * Description: We need no parameters:
- * Get the ioRefNum that we got from previously calling
- * CDOpen() by accessing the famous global
- * call the driver with a READTOC call to find out
- * the lead-out time. This is a unique number for each
- * disc. Look in the System Folder for the file
- * "CD Remote Programs". Open that file, look at the
- * IndX resource to find out if we've got a matching
- * index. If we do, look up the STR# resource
- * referenced and return the first STR from that list.
- *
- * 88 11 14 BL°B Add the ability to take an optional parameter
- * so that we look for the title of THAT track
- * instead.
- *
- ************************************************************************/
- pascal void
- CDTrackTitle(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- unsigned long discID;
- short trackNo, minute, second, block;
- Str255 title;
- Str31 returnString;
-
- trackNo = 0;
- strcpy(title, "\p");
-
- /* Must be no more than 1 parameter */
- if ((paramPtr->paramCount) > 1)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- result = IDDisc(ioRefNum, &discID);
-
- if (discID == 0)
- return; /* empty string return if we can't ID the disc */
-
- if (result == noErr)
- result = ReadQ(ioRefNum, &trackNo, &minute, &second, &block);
-
- /* If we were passed a track number, use it instead of the current track */
- if ((paramPtr->paramCount) == 1)
- trackNo = atoi((char *)*(paramPtr->params[0]));
-
- if (result == noErr)
- result = FindTrackTitle(discID, trackNo, &title);
-
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &title);
- }
-
-
-
- /************************************************************************
- *
- * Function: ReadQ
- *
- * Purpose: return current Q subcode address data
- *
- * Returns: OSErr. Probably either
- * noErr everything's hunky-dory!
- * paramErr you messed up the call somehow.
- *
- * Side Effects: none
- *
- * Description: Simply call the driver. Return track number and
- * absolute minute, second, block.
- *
- ************************************************************************/
- OSErr
- ReadQ(refNum, trackNo, minute, second, block)
- short refNum;
- short *trackNo;
- short *minute;
- short *second;
- short *block;
- {
- CDParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = READQ;
-
- result = PBControl(&myPB, false);
-
- if (result == noErr)
- {
- *trackNo = (short) BCD2DECIMAL(myPB.csParam[1]);
- *minute = (short) BCD2DECIMAL(myPB.csParam[6]);
- *second = (short) BCD2DECIMAL(myPB.csParam[7]);
- *block = (short) BCD2DECIMAL(myPB.csParam[8]);
- }
- return result;
- }
-
-
-
- /************************************************************************
- *
- * Function: FindTrackTitle
- *
- * Purpose: Find track title, given the disc ID
- *
- * Returns: OSErr. Usually noErr, but could have an error
- * in opening the CD Remote Programs file.
- *
- * Side Effects: fills in title with found title
- *
- * Description: open the file "CD Remote Programs". Look at the
- * 'IndX' resource to find out if we have a title.
- * If we can't find the appropriate 'IndX' resource,
- * set the title to blank and return. If we find
- * the appropriate IndX resource, open the 'ProG'
- * resource associated with this disc. Loop through
- * the 'ProG' resource to find where the track title
- * is located (the user may have used the CD Remote
- * desk accessory to change the order of the tracks.)
- * When you find the appropriate string number, use
- * GetIndString() to get the STR# string associated
- * with this track.
- *
- ************************************************************************/
- OSErr
- FindTrackTitle(discID, trackNo, title)
- unsigned long discID;
- short trackNo;
- Str255 *title;
- {
- OSErr result;
- short rsrcID; /* holds the 'STR#' & 'ProG' resource id. */
- short resFile;
- short *prog;
- Handle progHandle;
- short limit;
- short realTrackNo; /* 'ProG' may have different sequence */
- Str255 fileName;
-
- result = noErr;
-
- GetIndString(fileName, STR_ID, DRIVENAME);
- if (fileName == (Str255)0)
- result = ResError();
-
- if (result == noErr)
- {
- resFile = OpenSystemResFile(fileName);
- if (resFile == -1)
- result = ResError();
- }
-
-
- if (result == noErr)
- if (FindIndex(discID, &rsrcID) == true)
- {
- progHandle = Get1Resource('ProG', rsrcID);
- if (progHandle == nil)
- result = ResError();
- if (result == noErr)
- {
- prog = (short *) *progHandle;
- limit = prog[0];
- for (realTrackNo = 1; realTrackNo <= limit; realTrackNo++)
- {
- if (BCD2DECIMAL(prog[realTrackNo] & 0x00FF) == trackNo)
- GetIndString(title, rsrcID, realTrackNo+1);
- }
- }
- }
-
- CloseResFile(resFile);
- return result;
- }
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-